package com.ruoyi.material.util;

import java.text.SimpleDateFormat;
import java.util.*;

public class MapKeyComparator implements Comparator<String> {

    public int compare(String str1, String str2) {
        return str1.compareTo(str2);
    }
    /**
     * 获取当前日期前30天的日期(用于返回30天内血糖和血压)
     */
    public static Map<String, String> getDayMap(){
        SimpleDateFormat sdf  = new SimpleDateFormat("MM-dd");
        try {
            Calendar calc =Calendar.getInstance();
            Map<String, String> bloodMap = new HashMap<String, String>();
            for(int i=0;i<30;i++){
                calc.setTime(new Date());
                calc.add(calc.DATE, -i);
                Date minDate = calc.getTime();
                bloodMap.put(sdf.format(minDate), "0");
            }
            return bloodMap;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 使用 Map按key进行排序
     * @param map
     * @return
     */
    public static Map<String, String> sortMapByKey(Map<String, String> map) {
        if (map == null || map.isEmpty()) {
            return null;
        }
        Map<String, String> sortMap = new TreeMap<String, String>(new MapKeyComparator());
        sortMap.putAll(map);
        return sortMap;
    }
}
